package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.executor.httpclient.HttpClientUtils;
import org.springframework.stereotype.Component;

/**
 * 跨平台Http任务
 *
 * @author xuxueli 2018-09-16 03:48:34
 */
@JobHandler(value="restJobHandler")
@Component
public class RestJobHandler extends IJobHandler {

	@Override
	public ReturnT<String> execute(String param) throws Exception {

		// valid
		if (param==null || param.trim().length()==0) {
			XxlJobLogger.log("URL Empty");
			return FAIL;
		}
		String result = HttpClientUtils.get(param);
//		HttpResult httpResult = HttpClientUtils.get(param);
//		if (httpResult.getStatusCode() != HttpStatus.OK_200) {
//			XxlJobLogger.log("Http StatusCode({}) Invalid.", httpResult.getStatusCode());
//			return FAIL;
//		}
//
//		String responseMsg = httpResult.getContentTypeString();
//		if(responseMsg==null) {
//			return FAIL;
//		}
		XxlJobLogger.log(result);
		return SUCCESS;
	}

}
